var opacity = 0;
var fadein = false;
//Browser Support Code
function get_content(cmd){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('text');
			//fade out
			fadein = false;
			animateFadeout(50);
			//start trying to fade in
	//alert("rerender");			
			rerender(ajaxRequest);
		}
	}
	ajaxRequest.open("GET", "backend.php?cmd=" + cmd, true);
	ajaxRequest.send(null); 
}

function rerender(ajaxRequest){
	if(opacity <.04){
//alert("GOTHERE!");
		fadein = true;
		var ajaxDisplay = document.getElementById('text');	
		ajaxDisplay.innerHTML = ajaxRequest.responseText;
		animateFadein(100);
	}
	else{
		setTimeout(function(){rerender(ajaxRequest)}, (50));			
	}
}

function animateFadein(timeout)
{  
var element = document.getElementById("text");
  if(opacity < 1 && fadein){
   //alert("in " + opacity);
    opacity += .05;
    element.style.opacity = opacity;
    setTimeout("animateFadein("+timeout+")",(timeout*opacity));
  }
return true;
}


function animateFadeout(timeout)
{  
var element = document.getElementById("text");
  if(opacity > 0 && !fadein ){
   //alert("out " + opacity);
    opacity -= .05;
    element.style.opacity = opacity;
    setTimeout("animateFadeout("+timeout+")",(timeout*opacity));
  }
return true;
}
